package cn.wwcyc.controller;

import cn.wwcyc.domain.R;
import cn.wwcyc.domain.TjDw;
import cn.wwcyc.domain.TjGx;
import cn.wwcyc.domain.TjLog;
import cn.wwcyc.mapper.TjGxMapper;
import cn.wwcyc.service.TjDwService;
import cn.wwcyc.service.TjGxService;
import cn.wwcyc.service.TjLogService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

@RestController
@RequestMapping("/log")
public class LOGController {
//    @Autowired
//    TjGxService tjGxService;
//    @Autowired
//    TjGxMapper tjGxMapper;
//    @Autowired
//    TjDwService tjDwService;

    @Autowired
    TjLogService tjLogService;

    @GetMapping("/getpage")
    public R<IPage<TjLog>> getPage(
            @RequestParam(required = false) Integer pageNum,
            @RequestParam(required = false) Integer pageSize,
            @RequestParam(required = false) @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") Date start,
            @RequestParam(required = false) @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") Date end,
            @RequestParam(required = false) String jh) {

        if (pageNum == null) {
            pageNum = 1;
        }
        if (pageSize == null) {
            pageSize = 15;
        }
        LambdaQueryWrapper<TjLog> qw = new LambdaQueryWrapper<>();
        if (StringUtils.isNotBlank(jh)) {
            qw.like(TjLog::getOpcontent, jh);
        }
        if (end == null) {
            end = new Date();
        }
        if (start == null) {
            start = new Date();
        }
        qw.between(TjLog::getCreatedate, start, end);
        qw.orderByDesc(TjLog::getCreatedate);
        IPage<TjLog> page = new Page<>(pageNum, pageSize);
        tjLogService.page(page, qw);
        return R.success(page);
    }




}
